package com.task.manager.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;

import com.task.manager.domain.Task;

public interface TaskMapper {
	@Delete({ "delete from t_task", "where ID = #{id,jdbcType=INTEGER}" })
	int deleteByPrimaryKey(Integer id);

	@Insert({ "insert into t_task (ID, TASK_NAME, ", "TASK_CODE, TASK_HEADER, ", "TASK_TYPE, CALLBACK_ADDRESS, ", "TASK_PARAM, TASK_URL, ", "TASK_CRON, STATUS, RETRY_COUNT, ",
			"ACTUATOR_CODE, CREATE_TIME, ", "UPDATE_TIME)", "values (#{id,jdbcType=INTEGER}, #{taskName,jdbcType=VARCHAR}, ", "#{taskCode,jdbcType=VARCHAR}, #{taskHeader,jdbcType=VARCHAR}, ",
			"#{taskType,jdbcType=VARCHAR}, #{callbackAddress,jdbcType=VARCHAR}, ", "#{taskParam,jdbcType=VARCHAR}, #{taskUrl,jdbcType=VARCHAR}, ",
			"#{taskCron,jdbcType=VARCHAR}, #{status,jdbcType=BIT}, #{retryCount,jdbcType=INTEGER}, ", "#{actuatorCode,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, ",
			"#{updateTime,jdbcType=TIMESTAMP})" })
	int insert(Task record);

	@InsertProvider(type = TaskSqlProvider.class, method = "insertSelective")
	int insertSelective(Task record);

	@Select({ "select", "ID, TASK_NAME, TASK_CODE, TASK_HEADER, TASK_TYPE, CALLBACK_ADDRESS, TASK_PARAM, ", "TASK_URL, TASK_CRON, STATUS, RETRY_COUNT, ACTUATOR_CODE, CREATE_TIME, UPDATE_TIME",
			"from t_task", "where ID = #{id,jdbcType=INTEGER}" })
	@Results({ @Result(column = "ID", property = "id", jdbcType = JdbcType.INTEGER, id = true), @Result(column = "TASK_NAME", property = "taskName", jdbcType = JdbcType.VARCHAR),
			@Result(column = "TASK_CODE", property = "taskCode", jdbcType = JdbcType.VARCHAR), @Result(column = "TASK_HEADER", property = "taskHeader", jdbcType = JdbcType.VARCHAR),
			@Result(column = "TASK_TYPE", property = "taskType", jdbcType = JdbcType.VARCHAR), @Result(column = "CALLBACK_ADDRESS", property = "callbackAddress", jdbcType = JdbcType.VARCHAR),
			@Result(column = "TASK_PARAM", property = "taskParam", jdbcType = JdbcType.VARCHAR), @Result(column = "TASK_URL", property = "taskUrl", jdbcType = JdbcType.VARCHAR),
			@Result(column = "TASK_CRON", property = "taskCron", jdbcType = JdbcType.VARCHAR), @Result(column = "STATUS", property = "status", jdbcType = JdbcType.BIT),
			@Result(column = "RETRY_COUNT", property = "retryCount", jdbcType = JdbcType.INTEGER), @Result(column = "ACTUATOR_CODE", property = "actuatorCode", jdbcType = JdbcType.VARCHAR),
			@Result(column = "CREATE_TIME", property = "createTime", jdbcType = JdbcType.TIMESTAMP), @Result(column = "UPDATE_TIME", property = "updateTime", jdbcType = JdbcType.TIMESTAMP) })
	Task selectByPrimaryKey(Integer id);

	@UpdateProvider(type = TaskSqlProvider.class, method = "updateByPrimaryKeySelective")
	int updateByPrimaryKeySelective(Task record);

	@Update({ "update t_task", "set TASK_NAME = #{taskName,jdbcType=VARCHAR},", "TASK_CODE = #{taskCode,jdbcType=VARCHAR},", "TASK_HEADER = #{taskHeader,jdbcType=VARCHAR},",
			"TASK_TYPE = #{taskType,jdbcType=VARCHAR},", "CALLBACK_ADDRESS = #{callbackAddress,jdbcType=VARCHAR},", "TASK_PARAM = #{taskParam,jdbcType=VARCHAR},",
			"TASK_URL = #{taskUrl,jdbcType=VARCHAR},", "TASK_CRON = #{taskCron,jdbcType=VARCHAR},", "STATUS = #{status,jdbcType=BIT},", "RETRY_COUNT = #{retryCount,jdbcType=INTEGER},",
			"ACTUATOR_CODE = #{actuatorCode,jdbcType=VARCHAR},", "CREATE_TIME = #{createTime,jdbcType=TIMESTAMP},", "UPDATE_TIME = #{updateTime,jdbcType=TIMESTAMP}",
			"where ID = #{id,jdbcType=INTEGER}" })
	int updateByPrimaryKey(Task record);

	@Select({ " select ", " * ", " from t_task ","order by id desc" })
	List<Task> queryAll();

	@Select({ "select", "ID, TASK_NAME, TASK_CODE, TASK_PARAM, TASK_URL, TASK_CRON, RETRY_COUNT, ACTUATOR_CODE, ", "CREATE_TIME, UPDATE_TIME", "from t_task",
			"where TASK_CODE = #{taskCode,jdbcType=VARCHAR}" })
	Task selectByTaskCode(String taskCode);

	@SelectProvider(type = TaskSqlProvider.class, method = "queryTaskByParam")
	List<Task> queryTaskByParam(Task record);
}